/**
 * 无重复的最大值
 * @param {string} s
 * @return {number}
 */
var lengthOfLongestSubstring = function (s) {
    let mySet = new Set();
    let right = -1, length = 0;
    for (let left = 0; left < s.length; left++) {
        if (left != 0) {
            mySet.delete(s[left - 1]);
        }
        while (right + 1 < s.length && !mySet.has(s[right + 1])) {
            mySet.add(s[right + 1]);
            right++;
        }
        length = Math.max(length, right - left + 1)
    }
    return length;
};

const mySet=new Set();
mySet.add('a')
mySet.add('c')
mySet.add('b')
console.log(mySet);

let s = "abba"

function maxLength(s) {
  let left = 0, right = 0
  let map = {} // a: 0 b: 1 c: 2
  let count = 0

  while(right < s.length) {
    const char = s[right]

    if (char in map) {
      left = Math.max(left,map[char]+1) 
    }

    console.log(count,right-left);
    count = Math.max(count, right - left + 1)
    map[char] = right
    right++

  }
  return count
}
maxLength(s)